package myapps.ttclient.protocol.message;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import myapps.ttclient.Helper;
import myapps.ttclient.baseclass_and_interface.TTClientMessage;
import myapps.ttclient.struct.FileInformationStruct;


public class FileExploreResponseMessage extends TTClientMessage
{
	public String temporaryKey = "";
	
	public String directory;
	public FileInformationStruct[] fileInfos;
	
	public FileExploreResponseMessage(String temporaryKey, String directory, FileInformationStruct[] fileInfos)
	{
		this.temporaryKey = temporaryKey;
		this.directory = directory;
		this.fileInfos = fileInfos;
	}
	
	public static TTClientMessage parse(DataInputStream dis) throws IOException
	{	
		String key = Helper.ParseAsString(dis);
		
		String directory = Helper.ParseAsString(dis);
		
		int filesSize = dis.readInt();
		FileInformationStruct[] fileInfos = new FileInformationStruct[filesSize];
		
		for (int i = 0; i < filesSize; i++)
		{
			fileInfos[i] = new FileInformationStruct();
			fileInfos[i].path = Helper.ParseAsString(dis);
			fileInfos[i].type = dis.readInt();
		}
		
		return new FileExploreResponseMessage(key, directory, fileInfos);
	}
	
	@Override
	public void toDataOutputStream(DataOutputStream dos) throws IOException
	{
		throw new IOException("NotImplementedException");
	}
	
}
